package cn.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import cn.dto.Message;
import cn.dto.PageInfo;
import cn.dto.Result;
import cn.dto.common;
import cn.pojo.Category;
import cn.service.CategoryService;
import cn.service.impl.CategoryServiceImpl;

/**
 * 分类列表处理接口
 * @author 莫文聪
 *
 */
@WebServlet("/getCagetoryList")
public class getCagetoryList extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private CategoryService categoryService = new CategoryServiceImpl();
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//获取参数
		String categoryname = request.getParameter("categroy");
		String pageNostr = request.getParameter("pageNo");
		String pageSizestr = request.getParameter("pageSize");
		int pageNo = 1;
		int pageSize = 5;
		if(pageNostr!=null&&pageNostr!="") {
			pageNo = Integer.parseInt(pageNostr);
		}
		if(pageSizestr!=null&&pageSizestr!="") {
			pageSize = Integer.parseInt(pageSizestr);
		}
		PageInfo cagetoryList = categoryService.getCategory(pageNo, pageSize, categoryname);
		System.out.print("分类数据"+cagetoryList);
		Result result = new Result();
		result.setData(cagetoryList);
		result.setMessage(new Message(200,"成功"));
		response.getWriter().write(JSON.toJSONString(result));
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
